<?php
namespace app\api\controller;

use app\common\model\AttributionTrack;
use support\Request;

class LandingController
{
    public function track(Request $request)
    {
        $data = $request->post();
        $model = new AttributionTrack();
        $record = [
            'tracking_id' => $data['tracking_id'] ?? uniqid('trk_', true),
            'appkey' => $data['appkey'] ?? '',
            'fingerprint' => $data['fingerprint'] ?? '',
            'session_id' => $data['session_id'] ?? session_id(),
            'device_info' => $data['device_info'] ?? [],
            'custom_params' => $data['custom_params'] ?? [],
            'ip_address' => $request->getRealIp(),
            'user_agent' => $request->header('User-Agent', ''),
            'expire_time' => date('Y-m-d H:i:s', time() + 180 * 24 * 3600),
        ];
        $model->save($record);
        return json(['code' => 200, 'msg' => 'ok', 'data' => ['tracking_id' => $record['tracking_id']]]);
    }
}